package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.vo.ActiveConfigurationVo;
import com.juyu.miliao.api.service.ActiveConfigurationService;
import com.juyu.miliao.api.service.OpenApiService;
import com.juyu.miliao.common.domain.CommonHead;
import com.juyu.miliao.common.domain.OpenApiStatus;
import com.juyu.miliao.common.util.VerifyUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 *  活动配置控制器
 * @Auther: 卜加超
 * @Date: 2019/4/11 11:41
 * @Description:
 */
@RestController
@RequestMapping("activeConf")
public class ActiveConfigurationController {

    @Resource
    private ActiveConfigurationService activeConfigurationService;
    @Resource
    private OpenApiService openApiService;

    @GetMapping("/list")
    public List<ActiveConfigurationVo> getActive(@RequestParam(required = false)String activeId,
                                                 HttpServletRequest request){
        CommonHead com = VerifyUtil.verifyCommonHead(request);
        OpenApiStatus ops = openApiService.getOpenApi(com);
        if (ops != null && ops.getForwardAudit() && ops.getBackAudit()) {
            return new ArrayList<>();
        }
        int id = 0;
        if(!StringUtils.isEmpty(activeId)&&Integer.parseInt(activeId)>0){
            id = Integer.parseInt(activeId);
        }
        return activeConfigurationService.getActive(id);
    }
}
